<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #div{
            width: 500px;
            display: flex;
            justify-content: space-between;
        }
        #div div{
            width: 100px;
            height: 100px;
            background-color: #000;
        }
    </style>
</head>
<body>
    <button>点击吧div变成红色</button>
    <div id="div">
        <div></div>
        <div></div>
        <div></div>
    </div>
</body>
<script>
    window.onload=function(){
            var btn=document.getElementsByTagName('button')[0];
            var  divs=document.getElementById('div').getElementsByTagName('div')
            btn.onclick=function(){
                for(i=0;i<divs.length;i++){
                    divs[i].style.backgroundColor='red'
                }
            }
    }
</script>
</html>